import {defHttp} from '/@/utils/http/axios';
import {useMessage} from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/manageApi/caishuiServiceCompany/list',
  userList = '/manageApi/caishuiServiceCompany/userList',
  subUserList = '/manageApi/caishuiServiceCompany/subUserList',
  save='/manageApi/caishuiServiceCompany/add',
  edit='/manageApi/caishuiServiceCompany/edit',
  deleteOne = '/manageApi/caishuiServiceCompany/delete',
  deleteBatch = '/manageApi/caishuiServiceCompany/deleteBatch',
  importExcel = '/manageApi/caishuiServiceCompany/importExcel',
  exportXls = '/manageApi/caishuiServiceCompany/exportXls',
  bindingUser='/manageApi/caishuiServiceCompany/bindingUser',
  removeOne = '/manageApi/caishuiServiceCompany/removeOne',
  queryByCompanyId = '/manageApi/caishuiServiceCompany/queryByCompanyId',
  set = '/manageApi/caishuiServiceCompany/set',
  queryBranchByBankCode = '/manageApi/caishuiServiceCompany/queryBranchByBankCode',
  queryFilterRechargeRecords = '/manageApi/caishuiServiceCompany/queryFilterRechargeRecords',
  handleRechargeSave = '/manageApi/caishuiServiceCompany/handleRechargeSave',
}

/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;

/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 关联用户列表接口
 * @param params
 */
export const userList = (params) => defHttp.get({url: Api.userList, params});

/**
 * 中台用户列表接口
 * @param params
 */
export const subUserList = (params) => defHttp.get({url: Api.subUserList, params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}

/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
}

/**
 * 绑定用户
 * @param params
 */
export const bindingUser = (params) => {
  return defHttp.post({ url: Api.bindingUser, params }, { isTransformResponse: false });
}

/**
 * 移除单个服务公司中台用户
 * @param params
 * @param handleSuccess
 */
export const removeOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.removeOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 通过服务公司id查询配置
 * @param params
 */
export const queryByCompanyId = (params) => {
  return defHttp.get({ url: Api.queryByCompanyId, params }, { isTransformResponse: false });
}

/**
 * 配置银行秘钥
 * @param params
 */
export const set = (params) => {
  return defHttp.post({ url: Api.set, params }, { isTransformResponse: false });
}

/**
 * 根据开户行编码查询开户行分行
 * @param params
 */
export const queryBranchByBankCode = (params) => {
  return defHttp.get({ url: Api.queryBranchByBankCode, params }, { isTransformResponse: false });
}

/**
 * 查询服务公司历史交易记录
 * 筛选未入库的充值记录
 * @param params
 */
export const queryFilterRechargeRecords = (params) => {
  return defHttp.get({ url: Api.queryFilterRechargeRecords, params }, { isTransformResponse: false });
}

/**
 * 添加充值记录处理
 * @param params
 */
export const handleRechargeSave = (params) => {
  return defHttp.post({ url: Api.handleRechargeSave, params }, { isTransformResponse: false });
}
